//
//  ZDSettingController.m
//  TCProject
//
//  Created by admin on 16/2/3.
//  Copyright © 2016年 wise-wing. All rights reserved.
//

#import "ZDSettingController.h"
#import "WebViewController.h"
#import "AccountManager.h"

@interface ZDSettingController ()
@property (weak, nonatomic) IBOutlet UIButton *exitButton;

- (IBAction)exitAction:(id)sender;
@end

@implementation ZDSettingController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self.exitButton setBackgroundImage:[UIImage imageWithColor:kGlobalColor] forState:UIControlStateNormal];
    self.exitButton.layer.cornerRadius = 19.f;
    self.exitButton.layer.masksToBounds = YES;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 1) {
        [self alertWith:@"当前版本已为最新"];
    } else if (indexPath.row == 2) {    //使用指南
        WebViewController *webVC = [[WebViewController alloc] init];
        webVC.type = 1;
        [self showViewController:webVC sender:nil];
    } else if (indexPath.row == 4) {    //关于平台
        WebViewController *webVC = [[WebViewController alloc] init];
        webVC.type = 2;
        [self showViewController:webVC sender:nil];
    }
}

- (IBAction)exitAction:(UIButton *)sender {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否确定注销账号?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:cancleAction];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self logoutTask];
    }];
    [alertVC addAction:okAction];
    //    [cancleAction setValue:kGlobalColor forKeyPath:@"titleTextColor"];
    //    [okAction setValue:kGlobalColor forKeyPath:@"titleTextColor"];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)logoutTask {
    BMRequest *request = [BMRequest requestWithPath:@"loginOut.htm"];
    request.params = @{@"Id": @([AccountManager sharedInstance].user.ID), @"role": kRole};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (kResultOK == response.status) {
            [[AccountManager sharedInstance] logout];
            UIViewController *rootVC = self.navigationController;
            [self.navigationController popViewControllerAnimated:NO];
            UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            [rootVC presentViewController:[storyBoard instantiateViewControllerWithIdentifier:@"loginVC"] animated:YES completion:nil];
        } else {
            [self showHint:response.msg];
        }
    }];
}


@end
